import UniJsBridge from  "./uni-js-bridge"
const active = function(call){
  return new Promise(function(resolve,reject){
    if(process.env.VUE_APP_PLATFORM !='uniapp' && process.env.NODE_ENV !='development'){
      console.error('非app的正式环境下不允许调用SDK')
      reject(false);
      return;
    }
    call(resolve,reject)
  }) 
}
export const uni_scanCode = function(options={}):Promise<any>{
  return active((resolve,reject)=>{
    UniJsBridge.callHandler("uniscan", options,(res:any) => {resolve(res)});
  })
}
export const uni_setSorage = function(key,data):Promise<any>{
  return active((resolve,reject)=>{
    UniJsBridge.callHandler("setStorage", {key,data},(res:any) => {resolve(res)});
  })
}
export const uni_getSorage = function(key):Promise<any>{
  return active((resolve,reject)=>{
    UniJsBridge.callHandler("getStorage", key,(res:any) => {resolve(res)});
  })
}
export const uni_nfcRead = function(options={}):Promise<any>{
  return active((resolve,reject)=>{
    UniJsBridge.callHandler("nfcRead", options,(res:any) => {resolve(res)});
  })
}
export const uni_nfcWrite = function(str=''):Promise<any>{
  return active((resolve,reject)=>{
    UniJsBridge.callHandler("nfcWrite", str,(res:any) => {resolve(res)});
  })
}
export const uni_readFile = function(options={}):Promise<any>{
  return active((resolve,reject)=>{
    UniJsBridge.callHandler("readFile", options,(res:any) => {resolve(res)});
  })
}
